<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="任务编号" >
        <el-input
          v-model="queryParams.taskNumber"
          placeholder="请输入任务编号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="计划名称" >
        <el-input
          v-model="queryParams.planName"
          placeholder="请输入计划名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="计划编号" >
        <el-input
          v-model="queryParams.planNumber"
          placeholder="请输入计划编号"
          clearable
          size="small"
        />
      </el-form-item>

      <el-form-item label="计划时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          @change="jhchange(dateRange)"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="责任人" >
        <el-select
          v-model="queryParams.responsibilityUser"
          placeholder=""
          clearable
          size="small"
        >
          <el-option
            v-for="item in zerenOptions"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId">
          </el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="任务状态" >
        <el-select v-model="queryParams.taskStatus" multiple placeholder="请选择"  collapse-tags>
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
        <el-form-item label="执行时间">
          <el-date-picker
            v-model="dateRangeB"
            size="small"
            @change="jhchangeB(dateRangeB)"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-checkbox v-model="queryParams.checked" >我的任务</el-checkbox>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe >
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="任务编号" property="taskNumber" width="150" >
        <template slot-scope="scope" style="text-align: center">
          <span style="color: #2196F3;cursor: pointer" @click="xingqing(scope.row)">{{scope.row.taskNumber}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="责任人"   property="nickName" :show-overflow-tooltip="true" width="150" ></el-table-column>
      <el-table-column align="center" label="计划编号" property="planNumber" width="150" ></el-table-column>
      <el-table-column align="center" label="计划名称" property="planName" width="150" ></el-table-column>
      <el-table-column align="center" label="计划开始时间"  property="predictStartTime" width="150" ></el-table-column>
      <el-table-column label="计划结束时间" property="predictEndTime" align="center"width="150"> </el-table-column>
      <el-table-column align="center" label="任务状态"  property="taskStatus" :show-overflow-tooltip="true" width="100" >
        <template slot-scope="scope" style="text-align: center">
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.taskStatus=='1'" >未执行</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.taskStatus=='2'">执行中</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.taskStatus=='3'">已完成</div>
          <div style="background:#b5b5b5  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.taskStatus=='4'">已作废</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.taskStatus=='5'">已过期</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="实际开始时间" property="practicalStartTime"  width="150"  ></el-table-column>
      <el-table-column align="center" label="实际结束时间" property="practicalEndTime"  width="150"  ></el-table-column>
      <el-table-column align="center" label="延误天数"  property="delayDays"  ></el-table-column>
      <el-table-column align="center" label="应检设备数"   property="shouldExamineDeviceNumber"  width="100"  ></el-table-column>
      <el-table-column align="center" label="漏检设备数"   property="lackExamineDeviceNumber"   width="100"></el-table-column>
      <el-table-column align="center" label="异常设备数"   property="abnormalDeviceNumber"   width="100"></el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>

  import request from '@/utils/request'

  export default {
    name: "Role",
    data() {
      return {
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        dateRangeB:[],
        //责任人数据
        zerenOptions:[],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '未执行'},
          { value: '2',label: '执行中'},
          { value: '3',label: '已完成'},
          { value: '4',label: '已作废'},
          { value: '5',label: '已过期'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleName: undefined,
          roleKey: undefined,
          status: undefined,
          checked:true
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
      };
    },
    created() {
      this.getBgzrr()
      this.getList()


    },
    methods: {
      //变更责任人
      getBgzrr:function(){
        request({
          url: '/system/user/username',
          method: 'get',
        }).then(response => {
          this.zerenOptions = response.data
        });

      },
      //执行时间
      jhchangeB:function(data){
        this.queryParams.practicalStartTime =data[0]
        this.queryParams.practicalEndTime =data[1]
      },
      //计划时间
      jhchange:function(data){
        this.queryParams.predictStartTime =data[0]
        this.queryParams.predictEndTime =data[1]
      },
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        request({
          url: '/device/deviceInspectionTasks/list',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false;
          this.roleList = response.rows
          this.total = response.total
        });
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确定作废吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '作废成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消作废'
          });
        });
      },
      //详情点击
      xingqing:function (row) {
        console.log(row)
        this.$router.push({path:'/inspectionGL/inspectionXQ',query:{data:row}});
      },

    }
  };
</script>
